<template>
  <div class="dashboard">
    <h2>个人中心</h2>
    
    <!-- 数据概览卡片 -->
    <el-row :gutter="20" class="overview-cards">
      <el-col :span="12">
        <el-card class="overview-card">
          <template #header>
            <div class="card-header">
              <span>预约管理</span>
              <el-button type="primary" link @click="router.push('/user/appointment')">
                查看全部
                <el-icon><ArrowRight /></el-icon>
              </el-button>
            </div>
          </template>
          <div class="appointment-stats">
            <div class="stat-item">
              <span class="stat-value highlight">{{ pendingAppointments }}</span>
              <span class="stat-label">待完成预约</span>
            </div>
            <div class="next-appointment" v-if="nextAppointment">
              <h4>下次预约</h4>
              <p>{{ nextAppointment.date }} {{ nextAppointment.time }}</p>
              <p>{{ nextAppointment.doctorName }} 医生</p>
            </div>
          </div>
        </el-card>
      </el-col>

      <el-col :span="12">
        <el-card class="overview-card">
          <template #header>
            <div class="card-header">
              <span>最近咨询</span>
              <el-button type="primary" link @click="router.push('/user/history')">
                查看历史
                <el-icon><ArrowRight /></el-icon>
              </el-button>
            </div>
          </template>
          <div class="latest-consulting">
            <div class="consulting-info" v-if="latestConsulting">
              <h4>{{ latestConsulting.doctorName }} 医生</h4>
              <p class="consulting-time">{{ latestConsulting.date }} {{ latestConsulting.time }}</p>
            </div>
            <div class="no-data" v-else>
              暂无咨询记录
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ArrowRight } from '@element-plus/icons-vue'

const router = useRouter()

// 待完成预约数量
const pendingAppointments = ref(2)

// 下次预约信息
const nextAppointment = ref({
  date: '2024-03-20',
  time: '14:30',
  doctorName: '张'
})

// 最近测评结果
const latestTest = ref({
  name: '焦虑自评量表',
  date: '2024-03-15',
  score: 75
})

// 获取得分颜色
const getScoreColor = (score: number) => {
  if (score >= 80) return '#67C23A'
  if (score >= 60) return '#E6A23C'
  return '#F56C6C'
}

// 获取得分等级
const getScoreLevel = (score: number) => {
  if (score >= 80) return '状态良好'
  if (score >= 60) return '轻度焦虑'
  return '需要关注'
}
</script>

<style scoped>
.dashboard {
  padding: 20px;
}

h2 {
  margin: 0 0 30px;
  font-size: 24px;
  color: #2c3e50;
}

.overview-cards {
  margin-bottom: 30px;
}

.overview-card {
  height: 100%;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  font-weight: 600;
}

.appointment-stats {
  padding: 20px 0;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
}

.stat-value {
  font-size: 36px;
  font-weight: 600;
  color: #409EFF;
  margin-bottom: 8px;
}

.stat-label {
  font-size: 14px;
  color: #909399;
}

.next-appointment {
  border-top: 1px solid #EBEEF5;
  padding-top: 20px;
}

.next-appointment h4 {
  margin: 0 0 12px;
  font-size: 15px;
  color: #2c3e50;
}

.next-appointment p {
  margin: 8px 0;
  color: #606266;
}

.test-result {
  padding: 20px 0;
}

.test-info {
  margin-bottom: 20px;
}

.test-info h4 {
  margin: 0 0 8px;
  font-size: 15px;
  color: #2c3e50;
}

.test-date {
  font-size: 13px;
  color: #909399;
}

.test-score {
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.score-description {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.score-label {
  font-size: 14px;
  color: #909399;
}

.score-value {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
}

.no-data {
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #909399;
  font-size: 14px;
}
</style> 